
package com.myapp.c0910g.Utility;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


/**
 * @author "long.nguyen"
 *
 */
public class SendMailSSL {

    /**
     * @param args
     * @throws javax.mail.MessagingException
     * @throws
     * @throws AddressException
     */
    public void sendMailUtil(String email, String name)
        throws javax.mail.MessagingException, MessagingException {
        Properties props = new Properties();
        String body = "<h3>Dear Mr/Mrs. " + name + "</h3>" + "<br><br>";
        body += "Your account will be expired in 3 days. If you want to use out services." + "<br>"+
                "You check your account on our website." + "<br>" +
                "And pay the fee for using services." + "<br>" + "<br>" +
                "Thank you and Best Regards." + "<br>" +
                "Radio Cabs";

        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
            @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                                "longnd_a04615@fpt.aptech.ac.vn", "1123581321");
                    }
                });

        
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("longnd_a04615@fpt.aptech.ac.vn"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(email));
        message.setSubject("Radio Cabs Service");
        message.setContent(body, "text/html");

        Transport.send(message); 
    }

}
